<template>
  <div>
    <div style="margin-bottom: 20px">
      <el-input style="width:240px" placeholder="请输入标题" v-model="params.title"></el-input>
      <el-button style="margin-left: 5px " type="primary" @click="load"><i class="el-icon-search"></i>搜索</el-button>
      <el-button style="margin-left: 5px " type="warning" @click="reset"><i class="el-icon-refresh"></i>重置</el-button>
    </div>
    <el-table :data="tableData" stripe>
      <el-table-column prop="id" label="id"></el-table-column>
      <el-table-column prop="title" label="标题"></el-table-column>
      <el-table-column prop="body" label="正文">
        <template slot-scope="scope">
          <span>{{ scope.row.body.length > 10 ? scope.row.body.substring(0, 10) + '...' : scope.row.body }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="image"  label="图片">
        <template v-slot="scope">
          <el-image :src="scope.row.image" :preview-src-list="scope.row.image"></el-image>
        </template>
      </el-table-column>
      <el-table-column prop="createtime" label="创建时间"></el-table-column>
      <el-table-column label="操作">
        <template v-slot="scope">
          <!--scope就是当前行的数据-->     <!--点击跳转到这个路由，带上ID-->
          <el-button type="primary" @click="$router.push('EditnewFuzhou?id='+scope.row.id)" >编辑</el-button>
          <el-popconfirm
              style="margin-left: 5px"
              title="确认删除这行数据吗？"
              @confirm="del(scope.row.id)"
          >
            <el-button  type="danger" slot="reference" >删除</el-button>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>
    <div style="margin-top: 10px">
      <el-pagination
          background
          :page-size="params.pageSize"
          :current-page="params.pageNum"
          layout="prev, pager, next"
          @current-change="handleCurrentChange"
          :total="total">

      </el-pagination>
    </div>
  </div>
</template>

<script>
import request from "@/util/request";
export default {
  name: "newFuzhouBackground",
  data(){
    return{
      tableData:[],
      params:{
        pageNum:1,
        pageSize:5,
        title:"",
      },
    }
  },
  created() {
    this.load()
  },
  methods:{
    reset(){
      //重置按钮：直接把数据设置成默认
      this.params={
        pageNum:1,
        pageSize:10,
       title:"",
      }
      //再次调用查询所有
      this.load();
    },
    handleCurrentChange(pageNum){
      //点击分页按钮触发
      this.params.pageNum=pageNum;
      this.load();
    },
    load(){
      request.get("/newFz/page",{params:this.params}).then(res=>{
        if (res.code=='200'){
          this.tableData=res.data.list
          this.total=res.data.total

        }
      })
    },
    del(id){
      request.delete("/newFz/"+id).then(res=>{
        if (res.code=="200"){
          this.$notify.success("删除成功")
          this.load()
        }else{
          this.$notify.error(res.msg)
        }
      })
    }
  }
}
</script>

<style scoped>

</style>